unit Wizard;

interface

uses
  Database, SingleProfile,
  Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
  StdCtrls, Buttons, ExtCtrls, DB, Grids;

type
  TFormWizard = class(TForm)
    PanelMain: TPanel;
    BtnNext: TBitBtn;
    BtnBack: TBitBtn;
    BtnFinish: TBitBtn;
    LabelStep: TLabel;
    EditDesc: TMemo;
    Bevel1: TBevel;
    Edit1: TEdit;
    Label1: TLabel;
    Edit2: TEdit;
    Label2: TLabel;
    BtnCancel: TBitBtn;
    CheckScript: TCheckBox;
    PanelHow: TPanel;
    RBNew: TRadioButton;
    RBImport: TRadioButton;
    Bevel2: TBevel;
    BtnNew: TBitBtn;
    BtnImport: TBitBtn;
    PanelCreating: TPanel;
    LabelCreating: TLabel;
    ImageWizard: TImage;
    BtnMud: TBitBtn;
    MemoScript: TMemo;
    ImageWizardBase: TImage;
    Label3: TLabel;
    Edit3: TEdit;
    CheckCR: TCheckBox;
    DSMuds4: TDataSource;
    procedure FormCreate(Sender: TObject);
    procedure BtnCancelClick(Sender: TObject);
    procedure Edit1KeyPress(Sender: TObject; var Key: Char);
    procedure BtnNextClick(Sender: TObject);
    procedure BtnBackClick(Sender: TObject);
    procedure BtnNewClick(Sender: TObject);
    procedure CheckScriptClick(Sender: TObject);
    procedure BtnFinishClick(Sender: TObject);
    procedure EditDescClick(Sender: TObject);
    procedure RBNewClick(Sender: TObject);
  private
    { Private declarations }
    procedure SetupStep(which: integer; back: boolean);
  public
    { Public declarations }
  end;

var
  FormWizard: TFormWizard;
  step: integer;
  player, password, mud, host, port, trigger, website: string;
  created, foundmud, usecr: boolean;

implementation

{$R *.DFM}

procedure TFormWizard.FormCreate(Sender: TObject);
begin
  created:=false;
  PanelCreating.left:=164;
  PanelCreating.top:=127;
  PanelCreating.height:=40;
  PanelCreating.top:=120;
  with ImageWizard.canvas do begin
    brush.color:=clbtnface;
    BrushCopy(Bounds(0,0,32,31),ImageWizardBase.picture.bitmap,
      Bounds(0,0,32,31),clsilver);
  end;
  EditDesc.color:=clbtnface;
  foundmud:=false;
  LabelStep.caption:='';
  step:=1;
  player:='';
  password:='';
  mud:='';
  host:='';
  port:='';
  trigger:='elcome';
  website:='';
  usecr:=false;
  SetupStep(1,false);
  created:=true;
end;

procedure TFormWizard.RBNewClick(Sender: TObject);
begin
  BtnFinish.setfocus;
end;

procedure TFormWizard.EditDescClick(Sender: TObject);
begin
  if BtnNext.visible then BtnNext.setfocus else BtnFinish.setfocus;
end;

procedure TFormWizard.BtnCancelClick(Sender: TObject);
begin
  if (step = 1) and (Edit1.text = '') then begin
    close;
    exit;
  end;
  if messagedlg('Cancel the current character wizard?',
    mtconfirmation,[mbyes,mbno],0) = mryes then close;
end;

procedure TFormWizard.Edit1KeyPress(Sender: TObject; var Key: Char);
var which: integer;
begin
  which:=TComponent(sender).tag;
  if key = #13 then begin
    key:=#0;
    if step = 1 then BtnNext.click
    else if step = 2 then begin
      if which = 1 then begin
        if Edit1.text <> '' then Edit2.setfocus
        else BtnNext.click;
      end
      else BtnNext.click;
    end
    else if step = 3 then begin
      if which = 1 then begin
        if Edit1.text = '' then BtnMud.click
        else Edit2.setfocus;
      end
      else if which = 2 then begin
        Edit3.setfocus;
      end
      else BtnNext.click;
    end
    else if step = 4 then BtnNext.click
    else if step = 5 then BtnFinish.click;
  end;
end;

procedure TFormWizard.BtnBackClick(Sender: TObject);
begin
  dec(step);
  SetupStep(step,true);
end;

procedure TFormWizard.BtnNewClick(Sender: TObject);
begin
  case TComponent(sender).tag of
    1: begin
         RBNew.checked:=true;
         RBNew.setfocus;
       end;
    2: begin
         RBImport.checked:=true;
         RBImport.setfocus;
       end;
  end;
  BtnFinish.setfocus;
end;

procedure TFormWizard.CheckScriptClick(Sender: TObject);
begin
  if CheckScript.checked then begin
    MemoScript.lines.clear;
    MemoScript.lines.add('PLAYER');
    MemoScript.lines.add('PASSWORD');
  end
  else MemoScript.lines.clear;
end;

procedure TFormWizard.BtnNextClick(Sender: TObject);
begin
  case step of
    1: begin //Player
         if Edit1.text = '' then begin
           messagedlg('You must enter a player name',mtinformation,[mbok],0);
           Edit1.setfocus;
           exit;
         end;
         if Edit1.text <> lowercase(Edit1.text) then begin
           if messagedlg('You probably want the player name to be lowercase.  Alter it as such?',
             mtinformation,[mbyes,mbno],0) = mryes then begin
             Edit1.text:=lowercase(Edit1.text);
             exit;
           end;
         end;
         player:=Edit1.text;
         SetupStep(2,false);
       end;
    2: begin //Password
         if Edit1.text <> Edit2.text then begin
           messagedlg('The confirmation differs from the original',mtinformation,[mbok],0);
           Edit1.text:='';
           Edit2.text:='';
           Edit1.setfocus;
           exit;
         end;
         password:=Edit1.text;
         SetupStep(3,false);
       end;
    3: begin //Mud, Host, Port, Trigger (hidden)
         if Edit1.text = '' then begin
           messagedlg('You need to enter a name for the MUD',mtinformation,[mbok],0);
           Edit1.setfocus;
           exit;
         end;
         if (lowercase(Edit1.text) = 'connect') and (lowercase(player) = 'quick') then begin
           messagedlg('You can only create the Quick Connect profile from the login screen',
           mtinformation,[mbok],0);
           Edit1.setfocus;
           exit;
         end;
         if Edit2.text = '' then begin
           messagedlg('You need to enter a host for the MUD',mtinformation,[mbok],0);
           Edit2.setfocus;
           exit;
         end;
         if Edit3.text = '' then begin
           messagedlg('You need to enter a connection port for the MUD',mtinformation,[mbok],0);
           Edit3.setfocus;
           exit;
         end;
         mud:=Edit1.text;
         host:=Edit2.text;
         port:=Edit3.text;
         usecr:=CheckCR.checked;
         SetupStep(4,false);
       end;
    4: begin //Script
         SetupStep(5,false);
       end;
  end;
  inc(step);
end;

procedure TFormWizard.SetupStep(which: integer; back: boolean);
begin
  EditDesc.font.size:=8;
  EditDesc.font.name:='Arial';
  Label1.hide;
  Label2.hide;
  Label3.hide;
  Edit1.passwordchar:=#0;
  Edit1.hide;
  Edit2.passwordchar:=#0;
  Edit2.hide;
  Edit3.passwordchar:=#0;
  Edit3.hide;
  BtnMud.hide;
  CheckScript.hide;
  CheckCR.hide;
  MemoScript.hide;
  PanelHow.hide;
  BtnNext.show;
  BtnFinish.hide;
  case which of
    1: begin //Player
         //Description setup
         LabelStep.caption:='Choose Player Name';
         EditDesc.text:='Please enter the name of the player you wish to play.';
         //Controls setup
         Label1.left:=149;
         Label1.top:=166;
         Label1.caption:='&Player Name';
         Edit1.left:=Label1.left;
         Edit1.top:=Label1.top+15;
         Edit1.width:=142;
         Edit1.maxlength:=50;
         Edit1.text:=player;
         //Controls to show
         Label1.show;
         Edit1.show;
         //Other
         BtnBack.enabled:=false;
         Edit1.selectall;
         if created then Edit1.setfocus;
       end;
    2: begin //Password
         //Description setup
         LabelStep.caption:='Choose Password (optional)';
         EditDesc.text:='Please enter the password for the character.  '+
           'The password is case-sensitive (check your Caps Lock key!) and '+
           'cannot be more than 25 characters long - DON''T FORGET IT!  '+
           'If you choose not to enter your password now, '+
           'the system will prompt you whenever you need it.';
         //Controls setup
         Label1.left:=149;
         Label1.top:=146;
         Label1.height:=14;
         Label1.caption:='&Password';
         Edit1.left:=Label1.left;
         Edit1.top:=Label1.top+18;
         Edit1.width:=142;
         Edit1.maxlength:=25;
         Edit1.passwordchar:='*';
         Edit1.text:=password;
         Label2.left:=Label1.left;
         Label2.top:=194;
         Label2.height:=14;
         Label2.caption:='P&assword (confirm)';
         Edit2.left:=Label1.left;
         Edit2.top:=Label2.top+18;
         Edit2.width:=142;
         Edit2.maxlength:=25;
         Edit2.passwordchar:='*';
         Edit2.text:=password;
         //Controls to show
         Edit1.show;
         Label1.show;
         Edit2.show;
         Label2.show;
         //Other
         BtnBack.enabled:=true;
         Edit1.selectall;
         Edit1.setfocus;
       end;
    3: begin //Mud, Host, Port, Trigger (hidden)
         //Description setup
         LabelStep.caption:='Enter the MUD information';
         EditDesc.text:='Here you enter the information necessary for connecting '+
           'to the game that you wish.  You need to enter the name of the mud, '+
           'along with the host and port to connect to.  You can press the MUDs '+
           'button to select a MUD from the online listing.  You can always edit '+
           'this information later via the Player Profiles screen.';
         //Controls setup
         Label1.left:=115;
         Label1.top:=137;
         Label1.height:=14;
         Label1.caption:='&MUD Name';
         Edit1.left:=Label1.left;
         Edit1.top:=Label1.top+18;
         Edit1.width:=175;
         Edit1.maxlength:=100;
         Edit1.text:=mud;
         BtnMud.top:=Edit1.top;
         BtnMud.left:=Edit1.left+Edit1.width;
         Label2.left:=Label1.left;
         Label2.top:=183;
         Label2.height:=14;
         Label2.caption:='&Host';
         Edit2.left:=Label2.left;
         Edit2.top:=Label2.top+18;
         Edit2.width:=129;
         Edit2.maxlength:=100;
         Edit2.text:=host;
         Label3.left:=Label1.left+135;
         Label3.top:=Label2.top;
         Label3.height:=14;
         Label3.caption:='&Port';
         Edit3.left:=Label3.left;
         Edit3.top:=Label3.top+18;
         Edit3.width:=91;
         Edit3.maxlength:=25;
         Edit3.text:=port;
         CheckCR.left:=Label1.left;
         CheckCR.top:=232;
         CheckCR.height:=17;
         CheckCR.width:=317;
         CheckCR.checked:=usecr;
         //Controls to show
         Edit1.show;
         Label1.show;
         Edit2.show;
         Label2.show;
         Edit3.show;
         Label3.show;
         CheckCR.show;
         BtnMud.show;
         //Other
         Edit1.setfocus;
       end;
    4: begin //Script
         //Description setup
         LabelStep.caption:='Generate Login Script';
         EditDesc.text:='If you wish to automatically generate a login script '+
           'for this player profile, simply leave the checkbox '+
           'checked.  If you wish to login manually, then uncheck the checkbox.  '+
           'You can alter the script now if you wish and can also change it '+
           'later via the Player Profiles screen.  When the login script runs '+
           '(i.e. when you login), the words PLAYER and PASSWORD (as seen below) '+
           'are automatically substituted for the real values.';
         //Controls setup
         MemoScript.left:=131;
         MemoScript.top:=180;
         MemoScript.height:=61;
         MemoScript.width:=185;
         CheckScript.left:=MemoScript.left;
         CheckScript.top:=148;
         CheckScript.height:=17;
         CheckScript.width:=237;
         //Controls to show
         CheckScript.show;
         MemoScript.show;
         //Other
         CheckScript.setfocus;
       end;
    5: begin //Confirm
         //Description setup
         LabelStep.caption:='Confirm Character Profile';
         EditDesc.font.size:=10;
         EditDesc.font.name:='Courier New';
         EditDesc.lines.clear;
         EditDesc.lines.add('Player    - '+player);
         EditDesc.lines.add('MUD       - '+mud);
         EditDesc.lines.add('Host:Port - '+host+':'+port);
         if CheckScript.checked then EditDesc.lines.add('Script    - Yes')
         else EditDesc.lines.add('Script    - No');
         //Controls setup
         PanelHow.left:=8;
         PanelHow.top:=145;
         PanelHow.height:=93;
         PanelHow.width:=431;
         //Controls to show
         PanelHow.show;
         //Other
         BtnNext.hide;
         BtnFinish.show;
         BtnFinish.setfocus;
       end;
  end;
end;

procedure TFormWizard.BtnFinishClick(Sender: TObject);
var
  form: TFormProfile;
  wizpassed: boolean;
begin
  form:=TFormProfile.create(self);
  form.wizard:=true;
  form.EditPlayer.text:=player;
  form.EditPassword.text:=password;
  form.EditMUD.text:=mud;
  form.EditMUDHost.text:=host;
  form.EditMUDPort.text:=port;
  form.EditTrigger.text:=trigger;
  form.EditMUDWebsite.text:=website;
  form.CheckCR.checked:=usecr;
  form.CheckCR.checked:=usecr;
  if CheckScript.checked then begin
    form.MemoScript.lines.assign(MemoScript.lines);
  end;
  PanelCreating.show;
  PanelCreating.refresh;
  if RBNew.checked then form.BtnNew.click else form.BtnImport.click;
  PanelCreating.hide;
  wizpassed:=form.wizpassed;
  form.free;
  if wizpassed then close;
end;

end.

